using System;
using System.Diagnostics.Contracts;

namespace FluentWebRequest
{
    public class RequestSubmitter : IRequestSubmitter
    {
        private static volatile IRequestSubmitter _instance;
        private static readonly object SyncRoot = new Object();

        public static IRequestSubmitter GetInstance()
        {
            if (_instance == null)
            {
                lock (SyncRoot)
                {
                    if (_instance == null)
                        _instance = new RequestSubmitter();
                }
            }

            return _instance;
        }

        private RequestSubmitter()
        {
        }

        public IRequestDataBuilder WithUrl(string url)
        {
            Contract.Assert(!string.IsNullOrEmpty(url));

            return new RequestDataBuilder(url);
        }
    }
}